//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef	vector<int>             VI;
typedef	vector<bool>            VB;
typedef	vector<VI>              VVI;
typedef	vector<string>          VS;
typedef	pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef map<int,int>            MII;
typedef	pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()
#define INF                     (2000000000)

VB used;
VVI g;
VVI w;
VI tin;
VI tout;
int time;
VVI up;
int l;

void dfs(int v, int p=0) {
	used[v] = true;
	tin[v] = ++time;
	up[v][0] = p;
	FOR(i,1,l+1)
		up[v][i] = up[up[v][i-1]][i-1];
	FOR(i,0,SZ(g[v]))
		if( !used[ g[v][i] ] )
			dfs( g[v][i],v );
	tout[v] = ++time;
}

bool upper(int a, int b) {
	return ( tin[a] <= tin[b] && tout[a]>=tout[b] );
}

int LCA(int a, int b) {
	if( upper(a,b) ) return a;
	if( upper(b,a) ) return b;
	for(int i=l;i>=0;i--)
		if( !upper( up[a][i],b ) )
			a = up[a][i];
	return up[a][0];
}

int main()
{
	int n;
	scanf("%d",&n);
	g.resize(n);
	tout.resize(n);
	tin.resize(n);
	w.resize(n);
	used.resize(n);
	up.resize(n);
	time = 1;
	l = 1;
	while( (1<<l) <= n ) l++;
	FOR(i,0,n)
		up[i].resize(l+1);

	FOR(i,0,n-1) {
		int u,v,_w;
		scanf("%d%d%d",&u,&v,&_w);
		//u = i;v = i+1;_w = 1000;
		g[u].PB( v );
		w[u].PB( _w );
		g[v].PB( u );
		w[v].PB( _w );
	}

	dfs(0);

	used.clear();
	used.resize(n,false);
	queue<int> q;
	vector<i64> d(n,INF);
	d[0] = 0;
	q.push(0);
	used[0] = true;
	while( !q.empty() ) {
		int v = q.front();
		q.pop();
		FOR(i,0,SZ(g[v])) {
			if( !used[ g[v][i] ] ) {
				d[ g[v][i] ] = d[v] + w[v][i];
				used[ g[v][i] ] = true;
				q.push( g[v][i] );
			}
		}
	}

	int m;
	scanf("%d",&m);
	FOR(i,0,m) {
		int a,b;
		scanf("%d%d",&a,&b);
		int res = LCA(a,b);
		//cout << res << endl;

		int x = d[a] - d[res];
		int y = d[b] - d[res];
		res = x+y;
		cout << res << endl;
	}
    return 0;
}